package org.bl.chat.common.exception;

import org.bl.chat.common.dto.Response;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessesException.class)
    public Response<?> handleBusinessesException(BusinessesException ex) {
        return Response.fail(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Response<?> handleException(Exception ex) {
        ex.printStackTrace();
        return Response.fail(500, "服务器内部错误: " + ex.getMessage());
    }
}
